package com.wzdigit.wms.wms.service.mapping;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wzdigit.wms.basic.domain.mapping.CodeMapping;
import com.wzdigit.wms.basic.mapper.core.mapping.CodeMappingMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 内外部系统代码映射表 服务实现类
 * </p>
 *
 * @author
 * @since 2021-03-31
 */
@Service
@Slf4j
public class CodeMappingNewService {

    @Autowired
    private CodeMappingMapper codeMappingMapper;

    /**
     * 根据工厂和仓库CODE
     * 
     * @param factory
     * @param whsCode
     * @param qaStatus
     * @return
     */
    public CodeMapping selectByWhsCodeAndFactory(String factory, String whsCode, Integer qaStatus) {
        //创建类型的条件构造器
        QueryWrapper<CodeMapping> wrapper = new QueryWrapper<>();
        wrapper.eq("FAC_CODE", factory);
        wrapper.eq("WMS_CODE", whsCode);
        wrapper.eq("QA_STATUS", qaStatus);
        CodeMapping codeMapping = codeMappingMapper.selectOne(wrapper);
        return codeMapping;
    }

    /**
     * @param mappingCode
     * @param facCode
     * @return
     */
    public CodeMapping selectByMappingCodeAndFacCode(String mappingCode, String facCode) {
        //创建类型的条件构造器
        QueryWrapper<CodeMapping> wrapper = new QueryWrapper<>();
        wrapper.eq("CODE_TYPE","whs_code");
        wrapper.eq("MAPPING_SYSTEM", "SAP");
        wrapper.eq("MAPPING_CODE", mappingCode);
        wrapper.eq("FAC_CODE", facCode);
        CodeMapping codeMapping = codeMappingMapper.selectOne(wrapper);
        return codeMapping;
    }




    public CodeMapping selectByMappingCodeAndFacCodeAnyOne(String mappingCode, String facCode) {
        //创建类型的条件构造器
        QueryWrapper<CodeMapping> wrapper = new QueryWrapper<>();
        wrapper.eq("CODE_TYPE","whs_code");
        wrapper.eq("MAPPING_SYSTEM", "SAP");
        wrapper.eq("MAPPING_CODE", mappingCode);
        wrapper.eq("FAC_CODE", facCode);
        List<CodeMapping> list = codeMappingMapper.selectList(wrapper);

        if(list!=null && list.size()>0){
            return list.get(0);
        }else{
            return null;
        }
    }
}
